import { Component, ChangeDetectorRef, ChangeDetectionStrategy, Input, OnInit } from "@angular/core";
import { environment } from "../../../../../../../environments/environment";
import { BaseComponent } from "../../../../../../shared/components/baseComponent/base.component";
import { SustainableProductsAssessmentModel } from "../../models/companySustainableProducts.model";

/**
 * Controversy event indicator component
 *
 * Author: Andrei Istrate
 * Date: 10.12.2018
 */
@Component({
    moduleId: module.id,
    selector: 'sustainable-indicator',
    templateUrl: 'sustainableProductEventIndicator.component.html',
    styleUrls: [
        '../../../company.component.scss'/* ,
        '../../companyControversies.component.scss' */
    ],
    changeDetection: ChangeDetectionStrategy.Default
})
export class SustainableProductEventIndicatorComponent extends BaseComponent {
    public readonly resourcesUrl: string = environment.resourcesUrl;

    public _noExpand: boolean;

    get noExpand() {
        return !this.categoryHasInvolvement(this.category);
    }

    @Input() category: any;
    @Input() indicatorAssessments: any[];

    constructor(
        private cdRef: ChangeDetectorRef) {
        super(cdRef);
    }

    public getRevenuePercentage(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).revenuePercentage;
    }
    public getRevenueAnalysisSource(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).revenueAnalysisSource;
    }
    public getFinancialYear(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).financialYear;
    }
    public getProductInvolvementAnalysis(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).productInvolvementAnalysis;
    }
    public getRevenueAnalysis(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).revenueAnalysis;
    }
    public getSources(category: any) {
        return this.indicatorAssessments.find(x => x.categorySymbol == category.symbol).sources;
    }
    public categoryHasInvolvement(category: any): boolean {
        return this.indicatorAssessments.some(x => x.categorySymbol == category.symbol);
    }
}
